<?php namespace p5\objects;

class MobileUtils
{

    static public function hideMobiles(&$mobiles, $columnName = "mobile")
    {
        $len = count($mobiles);
        for ($i = 0; $i < $len; $i++) {
            $mobile = PropertyUtils::get($mobiles[$i], $columnName);
            if (is_array($mobile)) {
                $mobiles[$i][$columnName] = static::hideMobile($mobile);
            } else {
                $mobiles[$i]->$columnName = static::hideMobile($mobile);
            }
        }
    }

    static public function hideMobile($mobile)
    {
        if (empty($mobile)) {
            return "";
        }
        $len = strlen($mobile);
        if ($len <= 7) {
            if ($len > 3) {
                return substr($mobile, 0, 3) . "****";
            } else {
                return $mobile;
            }
        }
        return substr($mobile, 0, 3) . "****" . substr($mobile, $len - 4);
    }

    static public function hideMobilePart($mobile)
    {

    }

}